package com.game.model;

import com.game.interfaces.Blast;
import com.game.main.GameContext;
import com.game.util.ImageUtil;

import java.awt.*;
import java.util.concurrent.atomic.AtomicBoolean;

/**
 * @author: tjc
 * @Date: 2019-5-4
 */
public class TankBlast extends Blast {

    private int localX;
    private int localY;
    private int SIZE_X = 35;
    private int SIZE_Y = 35;

    private int step = 7;

    private AtomicBoolean life = new AtomicBoolean(false);

    public TankBlast(int x, int y) {
        localX = x;
        localY = y;
    }

    @Override
    public void draw(Graphics g) {
        if (step <= 0) {
            java.util.List<Blast>   blastList = GameContext.getContext().blastList;
            this.destroy();
        }
        g.drawImage(ImageUtil.tankBlastImages[step--], localX, localY, SIZE_X, SIZE_Y, null);
        SIZE_X += 3;
        SIZE_Y += 3;
    }

    @Override
    public void init() {
        life.set(true);
    }

    @Override
    public void destroy() {
        life.set(false);
    }

    @Override
    public boolean alive() {
        return life.get();
    }
}
